package com.ruoyi.app.lease.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.app.lease.domain.LeaseEquipmentInfo;
import com.ruoyi.app.lease.service.ILeaseEquipmentInfoService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.page.PageParam;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 用户信息Controller
 *
 * @author ldl
 * @date 2023-10-15
 */
@Slf4j
@RestController
@RequestMapping("/lease/equipment")
@Api(tags = "设备租赁信息表")
public class LeaseEquipmentInfoController {
    @Autowired
    private ILeaseEquipmentInfoService leaseEquipmentInfoService;

    @Anonymous
    @PostMapping("/test")
    @ApiOperation("测试1")
    public Result<Date> test(@RequestParam(required = false) Date s, @RequestBody(required = false) LeaseEquipmentInfo b) {
        log.info("---------------------------------s:{}", s);
        log.info("---------------------------------b:{}", b);
        return Result.success(s);
    }

    @Anonymous
    @PostMapping("/test1")
    @ApiOperation("测试2")
    public Result<LeaseEquipmentInfo> test(@RequestParam(required = false) LeaseEquipmentInfo b, @RequestBody String deptId) {
        log.info("---------------------------------b:{}", b);
        if (!deptId.equals("1")) {
            throw new ServiceException("测试异常");
        }
        return Result.success(b);
    }

    /**
     * 查询用户信息列表
     */
    @ApiOperation("查询用户信息列表")
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public Result<List<LeaseEquipmentInfo>> list(PageParam page, LeaseEquipmentInfo leaseEquipmentInfo) {
        List<LeaseEquipmentInfo> list = leaseEquipmentInfoService.list(new Page<>(page.getPageNum(), page.getPageSize()), new QueryWrapper<>(leaseEquipmentInfo));
        return Result.success(list);
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public Result<LeaseEquipmentInfo> getInfo(@PathVariable("id") String id) {
        return Result.success(leaseEquipmentInfoService.getById(id));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@RequestBody LeaseEquipmentInfo leaseEquipmentInfo) {
        return Result.toAjax(leaseEquipmentInfoService.save(leaseEquipmentInfo));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> edit(@RequestBody LeaseEquipmentInfo leaseEquipmentInfo) {
        return Result.toAjax(leaseEquipmentInfoService.updateById(leaseEquipmentInfo));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result<Void> remove(@PathVariable List<String> ids) {
        return Result.toAjax(leaseEquipmentInfoService.removeByIds(ids));
    }
}
